#include <bits/stdc++.h>
// 2025/01/27
// tag: 
// Author: Zhang Muen
using namespace std;

vector<int> graph[65536];
bool vis[65536];

int myswap(int x, int pos){
    int i = -1, j = -1;
    for (int k = 0; k < 16; k++)
        if (pos & (1 << k))
            if (i == -1)
                i = k;
            else
                j = k;
    bool a = x & (1 << i), b = x & (1 << j);
    if (a)
        x |= (1 << j);
    else
        x &= ~(1 << j);
    if (b)
        x |= (1 << i);
    else
        x &= ~(1 << i);
    return x;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int START = 0, END = 0;
    string s;
    for (int i = 3; i >= 0; i--)
    {
        cin >> s;
        START |= (s[0] == '1') << (i * 4 + 3);
        START |= (s[1] == '1') << (i * 4 + 2);
        START |= (s[2] == '1') << (i * 4 + 1);
        START |= (s[3] == '1') << (i * 4);
    }
    for (int i = 3; i >= 0; i--){
        cin >> s;
        END |= (s[0] == '1') << (i * 4 + 3);
        END |= (s[1] == '1') << (i * 4 + 2);
        END |= (s[2] == '1') << (i * 4 + 1);
        END |= (s[3] == '1') << (i * 4);
    }
    queue<int> q;
    q.push(START);
    vis[START] = true;
    while (!q.empty()){
        int x = q.front();
        q.pop();
        if (x == END)
            break;
        for (int i = 0; i < 16; i++){
            if (i + 4 < 16){
                int y = myswap(x, (1 << i) | (1 << (i + 4)));
                if (!vis[y]){
                    vis[y] = true;
                    graph[y] = graph[x];
                    graph[y].push_back((1 << i) | (1 << (i + 4)));
                    q.push(y);
                }
            }
            if (i - 4 >= 0){
                int y = myswap(x, (1 << i) | (1 << (i - 4)));
                if (!vis[y]){
                    vis[y] = true;
                    graph[y] = graph[x];
                    graph[y].push_back((1 << i) | (1 << (i - 4)));
                    q.push(y);
                }
            }
            if (i % 4 != 3){
                int y = myswap(x, (1 << i) | (1 << (i + 1)));
                if (!vis[y]){
                    vis[y] = true;
                    graph[y] = graph[x];
                    graph[y].push_back((1 << i) | (1 << (i + 1)));
                    q.push(y);
                }
            }
            if (i % 4 != 0){
                int y = myswap(x, (1 << i) | (1 << (i - 1)));
                if (!vis[y]){
                    vis[y] = true;
                    graph[y] = graph[x];
                    graph[y].push_back((1 << i) | (1 << (i - 1)));
                    q.push(y);
                }
            }
        }
    }
    cout << graph[END].size() << endl;
    for (auto x: graph[END]){
        int i = -1, j = -1;
        for (int k = 0; k < 16; k++)
            if (x & (1 << k))
                if (i == -1)
                    i = k;
                else
                    j = k;
        cout << 4 - i / 4 << 4 - i % 4 << 4 - j / 4 << 4 - j % 4 << endl;
    }
    return 0;
}